﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using NetDon.OA.Interface.Common;
using NetDon.Utilities;
using NetDon.WebControls;

namespace NetDon.OA.Portal.Admin
{
    public class RouteInfoPresenter : Presenter<IRouteInfoView>
    {
        public override void OnViewInitialized()
        {
            PopulateRoutes();
        }



        public override void OnViewLoaded()
        {
            View.RefereshRoutes += new EventHandler(View_RefereshRoutes);
            View.RemoveRoute += new EventHandler<EventArgs<Guid>>(View_RemoveRoute);
        }

    

        void View_RefereshRoutes(object sender, EventArgs e)
        {

            PopulateRoutes();
        }


    

        void View_RemoveRoute(object sender, EventArgs<Guid> e)
        {
            var service = ServiceContainer.GetService<IRouteInfoService>();
            if (service.CheckRouteReferenced(e.Data))
            {
                View.Alert("该路线已经被出单信息使用，不可以删除。");
                return;
            }
            if (service.RemoveRoute(e.Data))
            {
                PopulateRoutes();
            }
        }

        private void PopulateRoutes()
        {
            var service = ServiceContainer.GetService<IRouteInfoService>();
            View.PopulateRoutes(service.GetRoutes());
        }
    }
}
